<template>
	<view class="pageBg">
		<addresschoice @addressChange="addressChange"></addresschoice>
		<view class="goodsdetails">
			<view class="goodsBox">
				<goods-view class="goods" :src="goods.image"></goods-view>
				<view class="txtBox">
					<view class="title">
						{{ goods.name }}
					</view>
					<view class="userPic">
						<view class="price ellipsis">
							{{ price }}
						</view>
						<view class="calculator">
							<image @click.stop="reduce()" class="icon reduce verticalMiddle" src="/static/images/reduce.png" mode=""></image>
							<text class="num">x{{ goods_num || 0 }}</text>
							<image @click.stop="add()" class="icon add verticalMiddle" src="/static/images/add.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="subtotal">
			<view class="descView spaceBetween">
				<view class="labe">配送方式</view>
				<view class="">快递￥{{ goods.express_money }}</view>
			</view>
			<view class="line"></view>
			<view class="bot flex">
				<text class="Total">共{{ goods_num }}件</text>
				<text class="labe">小计：</text>
				<text class="val">￥ {{ subtotal }}</text>
			</view>
		</view>
		<view class="optBottomPay">
			<view class="Total flex">
				<view class="labe">总计:</view>
				<view class="num">￥{{ subtotal }}</view>
			</view>
			<view class="btn" @click="goPay">提交订单</view>
		</view>
	</view>
</template>

<script>
	import { WxPay } from '@/utils/pay.js';
	import addresschoice from '@/components/product/address/address.vue';
	import goodsView from '@/components/my/goodsList/goods/goods.vue';
	import math from '@/utils/calc.js';
	export default {
		components: {
			addresschoice,
			goodsView,
		},
		mixins: [WxPay],
		computed: {
			subtotal() {
				return math.add(this.goods.express_money, math.multiply(this.price, this.goods_num));
			},
		},
		data() {
			return {
				price: 0,
				goods_num: 1,
				GoodsItem: null,
				address_id: null,
			};
		},
		beforeDestroy() {},
		onHide() {},
		onLoad({ GoodsItem, id }) {
			this.goods = uni.getStorageSync('orderData');
			this.price = this.goods.GoodsItem[GoodsItem].price;
			this.GoodsItem = GoodsItem;
		},
		methods: {
			addressChange(id) {
				console.log('address_id', id);
				this.address_id = id;
			},
			reduce(index) {
				--this.goods_num;
			},
			add(index) {
				++this.goods_num;
			},
			async goPay() {
				uni.showLoading();
				const { data } = await this.$api.OrderSubmitOrder({ goods_id: this.goods.id, GoodsItem: this.GoodsItem, address_id: this.address_id, goods_num: this.goods_num });

				const res = await this.$api.payUnifiedpay({ order_id: data.order_id, url: '/pages/my/order/order' });
			},
		},
	};
</script>

<style lang="scss" scoped>
	.pageBg {
		overflow: hidden;
		padding-bottom: 200rpx;

		.goodsdetails {
			width: $connet-width;
			min-height: 220rpx;
			background: $content-bg-colcor;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			margin: $margin-width auto;
			overflow: hidden;

			.goodsBox {
				overflow: hidden;
				display: flex;
				align-items: center;
				margin-top: $submargin-width;

				.goods {
					width: 160rpx;
					height: 160rpx;
					overflow: hidden;
					margin-left: $margin-width;
					margin-right: $margin-width;
				}
			}

			.txtBox {
				height: 160rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				width: 440rpx;

				.title {
					font-size: $uni-font-size-13;
					color: $title-colcor;
				}

				.userPic {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.price {
						font-weight: bold;
						color: $price-color;
						margin-right: $submargin-width;
						font-size: $uni-font-size-14;
					}

					// .num {
					// 	font-size: $uni-font-size-12;
					// 	color: $unselected;
					// }
					.calculator {
						display: flex;
						float: right;
						align-items: center;
						.icon {
							width: 45rpx;
							height: 45rpx;
						}

						.num {
							color: $title-color;
							margin: 0 10rpx;
							font-size: $uni-font-size-16;
						}
					}
				}
			}
		}
		.subtotal {
			width: 690rpx;
			height: 176rpx;
			background: #ffffff;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			margin: 25rpx auto;
			.descView {
				width: 630rpx;
				margin: 0 auto;
				font-size: $uni-font-size-12;
				color: #000000;
				align-items: center;
				line-height: 96rpx;
			}
			.line {
				border-top: 1rpx solid #dddddd;
				margin: 0 auto;
				width: 630rpx;
			}
			.bot {
				width: 630rpx;
				margin: 0 auto;
				justify-content: end;
				align-items: center;
				height: 80rpx;
				.Total {
					font-size: $uni-font-size-12;
					color: #999999;
				}
				.labe {
					font-size: $uni-font-size-14;
					color: #000000;
				}
				.val {
					font-weight: bold;
					font-size: $uni-font-size-14;
					color: $price-color;
				}
			}
		}
		.optBottomPay {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 160rpx;
			background: #ffffff;
			line-height: 160rpx;
			overflow: hidden;
			.Total {
				float: left;
				display: flex;
				margin-left: $margin-width;
				font-size: $uni-font-size-14;
				font-weight: bold;
				color: $title-colcor;
				.num {
					color: $price-color;
				}
			}
			.btn {
				background-color: $price-color;
				color: $txt-color;
				width: 180rpx;
				height: 80rpx;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				line-height: 80rpx;
				float: right;
				margin-right: $margin-width;
				margin-top: 40rpx;
				text-align: center;
				font-size: $uni-font-size-15;
			}
		}
	}
</style>
